home *** CD-ROM | disk | FTP | other *** search
- Path: american.edu!JW1675A
- From: JW1675A@american.edu (James D. Watson)
- Newsgroups: comp.lang.c
- Subject: more problems with qsort
- Date: Mon, 26 Feb 96 10:44:18 EST
- Organization: The American University
- Message-ID: <177399702S86.JW1675A@american.edu>
- NNTP-Posting-Host: auvm.american.edu
-
- Hi folks --
-
- after reading the FAQ entries about qsort, I thought I had my problem
- licked, but it seems not.
-
- Architecture: SunOS 4.1.3 with ANSI-C compiler.
-
- I'm doing some file manipulation and between steps A and B, I need to sort.
- For various reasons, I don't want to popen() to the sort utility--I want to
- use qsort. Here's what I'm doing:
-
- get number of lines in the file
- (char**)malloc with enough room for all lines
- for each line in the file {
- (char*)malloc(90) /* 90 is enough room for each line in file */
- copy each line into the newly malloc()ed space
- point a (char**) to the newly malloc()ed space
- }
-
- so now I should have "lines" number of pointers to pointers to char,
- each one pointing to 90 bytes containing a line in the file.
-
- So, I call qsort(array[0], lines, 90, compare)
- where compare is my comparison function -- prepared as discussed
- in the FAQ. Now all I get are core dumps during the call to qsort().
- :-)
-
- The core dump isn't in my compare routine -- it's somewhere else in
- the qsort() function according to dbx -- so I'm sure it's a problem
- setting up my data.
-
- Any tips? Much appreciation in advance,
- Regards,
- Jim
-